package appConfig

import (
	"fmt"
	"github.com/spf13/viper"
)

type Mysql struct {
	Host     string `yaml:"host"`
	Port     int    `yaml:"port"`
	User     string `yaml:"user"`
	Password string `yaml:"password"`
	Database string `yaml:"database"`
}
type Redis struct {
	Host     string `yaml:"host"`
	Port     int    `yaml:"port"`
	Password string `yaml:"password"`
	Database int    `yaml:"database"`
}
type Qiniuyun struct {
	AccessKey string `yaml:"accessKey"`
	SecretKey string `yaml:"secretKey"`
	Bucket    string `yaml:"bucket"`
	Url       string `yaml:"url"`
}
type SendSms struct {
	APIID  string `yaml:"APIID"`
	APIKEY string `yaml:"APIKEY"`
}
type AppConfig struct {
	Mysql
	Redis
	Qiniuyun
	SendSms
}

var Config *AppConfig

func Init() {
	viper.SetConfigFile("../appConfig/dev.yaml")
	err := viper.ReadInConfig()
	if err != nil {
		panic(err)
	}
	err = viper.Unmarshal(&Config)
	if err != nil {
		panic(err)
	}
	fmt.Println(Config)
}
